<include file="Forum:header"/>
<body>
<div class="topic-wrap new-article-wrap add-reply hide">
    <header class="talk-header talk-detail-header"><span class="iconfont go-back"></span>
        <p class="text-center">发表回复</p>
    </header>
    <div class="add-topic">
        <textarea placeholder="输入文字" class="content" id="content"></textarea>
        <div class="emoji-container"><div class="emoji-wrap"><div class="emoji-btn iconfont"  id="express"></div><div class="emoji-list" style="height:380px;"></div></div></div>
        <div class="comment-wrap"><a id="submit-comment" href="javascript:void(0);" class="comment-btn">发表</a></div>
    </div>
</div>
<input type="hidden" id="show">
<input type="hidden" id="post_id" value="{BEESCRM:$post_id}" >
<input type="hidden" id="user_id" value="{BEESCRM:$user_id}" >
<include file="Forum:commonjs"/>
<script>
    $(function(){
        FastClick.attach(document.body);
        //   点击导航
        $('.menu-btn').on('click', function () {
            $(this).toggleClass('active');
            $('.menu-list').toggleClass('active');
        });
    });
    $('body').click(function(){
    	var show = $('#show').val();
    	if(show){
    		$('.emoji-list').hide();
    		$('#show').val('');
    		$(".emoji-list").html('');
    	}
    });
    $('.go-back').click(function(){
		history.go(-1);
	});
    $('#express').click(function(){
    	$.ajax({
    		type:'post',
    		url:'{BEESCRM::U('base/railwayForum/expression',array('forum_id' => $forum_id))}',
    		data:{},
    		dataType:'json',
    		success:function(data){
    			var html = '';
    			$.each(data.data,function(i,item){
    				html += '<span class="item" data-code="'+item.code+'"><img src="'+item.url+'"></span>';
    			});
    			$(".emoji-list").append(html).addClass('show');
    			$('#show').val(1);
    			if($(".emoji-list").is(":hidden")){
    				$('.emoji-list').show();
    			}
    		},
    		error:function(){
    			$.toast('error','通讯错误');
    		},
    	});
    });
    $(document).on('click','.item',function(){
    	var content = $('#content').val();
    	
    	$('#content').val(content + $(this).data('code'));
    	$(".emoji-list").removeClass('show');
    });
    $('#submit-comment').click(function(){
    	var parent_id = $('#post_id').val();
    	var content = $('#content').val();
    	var reply_to_user_id = $('#user_id').val();
    	if(!content){
    		$.toast('error','您还未输入文字内容');return false;
    	}
    	$.ajax({
    		type:'post',
    		url:'{BEESCRM::U('base/railwayForum/doGetReply',array('forum_id' => $forum_id))}',
    		data:{'parent_id':parent_id,'content':content,'reply_to_user_id':reply_to_user_id},
    		dataType:'json',
    		success:function(data){
    			if(data.status == 'S'){
    				$.toast('success',data.message);
    				setTimeout(function(){
    					location.href = data.url;
    				},3000);
    			}else {
    				$.toast('error',data.message);
    			}
    		},
    		error:function(){
    			$.toast('error','通讯错误');
    		},
    	});
    });
</script>
</body>
</html>